// Score reading & writting

var file;

switch(global.opt)
{
case "read":
if(!file_exists(working_directory + global.hiscorefile))
{
    file = file_text_open_append(working_directory + global.hiscorefile);
} else {
    
    file = file_text_open_read(working_directory + global.hiscorefile);
    while(!file_text_eof(file))
    {
        fileline = file_text_read_string(file)
        scorefilename = string_letters(fileline);
        scorefilevalue = string_digits(fileline);
        highscore_add(scorefilename,real(scorefilevalue));
        file_text_readln(file);
    }
}
file_text_close(file);

break;

case "write":
if(global.playername <> "" && score > 0)
{
file = file_text_open_append(working_directory + global.hiscorefile);
    file_text_write_string(file,global.playername + " ");
    file_text_write_real(file,score);
    file_text_writeln(file);
    file_text_close(file);
}
break;
}

